import {axios} from '../utils/request'
import {COUPON_MODULE,COUPON1_MODULE} from './_prefix'

type ceoCreateInfo = {
    couponCount : number
    couponType : number
    fullAmount ?: number
    discountAmount ?: number
    storeId ?: number
}

type staffCreateInfo = {
    couponCount : number
    couponType : number
    fullAmount ?: number
    discountAmount ?: number
}

type discountPrice = {
    price : number
    couponGroupID : number[]
}

type useableInfo = {
    storeId : number
    price : number
    chosenTypes: number[]
}

//CEO发布优惠券
export const ceoCreate = (CouponCreate : ceoCreateInfo) => {
    return axios.post(`${COUPON_MODULE}/ceo_create`,CouponCreate,{headers: {'Content-Type': 'application/json'}})
        .then(res => {
            return res;
        })
}


//工作人员发布优惠券
export const staffCreate = (CouponCreate : staffCreateInfo) => {
    return axios.post(`${COUPON_MODULE}/staff_create`,CouponCreate,{headers: {'Content-Type': 'application/json'}})
        .then(res => {
            return res;
        })
}


//获取优惠券组信息
export const couponInfo = ()=>{
    return axios.get(`${COUPON_MODULE}/info`)
        .then(res =>{
            return res;
        })
}

//根据id获取优惠券组信息
export const singleCouponInfo = (couponId : number) =>{
    return axios.post(`${COUPON_MODULE}/get_coupon_group`, null, {params: {id:couponId}})
        .then(res => {
            return res
        })
}

//领取优惠券
export const receive = (couponId : number) =>{
    return axios.post(`${COUPON_MODULE}/receive`, null, {params: {id:couponId}})
        .then(res => {
            return res
        })
}

//获取能使用的优惠券
export const useCoupon = (useableInfo : useableInfo) =>{
    return axios.post(`${COUPON1_MODULE}/get_all_coupons`,useableInfo,{headers: {'Content-Type': 'application/json'}})
        .then(res =>{
            return res;
        })
}

//优惠量
export const discount = (dis : discountPrice) =>{
    return axios.post(`${COUPON_MODULE}/discount`, dis,{headers: {'Content-Type': 'application/json'}})
        .then(res => {
            return res
        })
}